package com.yuyou.fn.common.lang;

import java.util.HashMap;
import java.util.Map;

public class Tuple2<T1,T2> extends Tuple {

    private T1 first ;

    private T2 second ;

    public Tuple2(T1 first, T2 second) {
        this.first = first;
        this.second = second;
    }

    public T1 getFirst() {
        return first;
    }

    public void setFirst(T1 first) {
        this.first = first;
    }

    public T2 getSecond() {
        return second;
    }

    public void setSecond(T2 second) {
        this.second = second;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Tuple2<?, ?> tuple2 = (Tuple2<?, ?>) o;

        if (first != null ? !first.equals(tuple2.first) : tuple2.first != null) return false;
        return second != null ? second.equals(tuple2.second) : tuple2.second == null;
    }

    @Override
    public int hashCode() {
        int result = first != null ? first.hashCode() : 0;
        result = 31 * result + (second != null ? second.hashCode() : 0);
        return result;
    }

    public static <T1,T2> Tuple2<T1,T2> of(T1 first ,T2 second ){
        return new Tuple2<>(first,second);
    }

    public static <T1,T2> Map<T1,T2> asMap( Tuple2<T1,T2> ... tuple2s ){
        Map<T1,T2> map = new HashMap<>();
        for(Tuple2<T1,T2> tuple2 : tuple2s ){
            map.put(tuple2.first,tuple2.second );
        }
        return map;
    }
}
